package com.itguigu.fruit.impl;

import com.atguigu.mymvc.BaseDao;
import com.itguigu.fruit.dao.FruitDao;
import com.itguigu.fruit.pojo.Fruit;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class FruitDaoImpl extends BaseDao<Fruit> implements FruitDao {


    @Override
    public void addFruit(Fruit fruit) {
        String sql="insert into t_fruit values(null,?,?,?,?)";
super.update(sql,fruit.getFname(),fruit.getPrice(),fruit.getFcount(),fruit.getRemark());


    }

    @Override
    public void delFruit(String fname) {
        String sql = "delete  from t_fruit where fname=?";
        super.update(sql,fname);
           }

    @Override
    public void updateFruit(Fruit fruit) {
        String sql = "update t_fruit set fcount=? where fname=?";
        super.update(sql,fruit.getFcount(), fruit.getFname());

    }

    @Override
    public List<Fruit> getFruitList() {
        String sql = "select * from t_fruit";
        return super.query(sql);
    }

    @Override
    public Fruit getFruitByFname(String fname) {
        String sql = "select * from t_fruit where fname=?";
        return queryByFname(sql,fname);
    }
}
